import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'navigate_page.dart';
import 'login_page.dart';
import '../provider/_providers.dart';

class RootPage extends StatefulWidget {
  const RootPage({Key? key}) : super(key: key);

  @override
  _RootPageState createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {

  /// Views to display
  ///
  List<Widget> views = [LoginScreen(), NavigatePage()];
  int selectedIndex = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Consumer(
      builder: (context, ref, _) {

        bool authed = ref.watch(userProvider).authed;

        if (authed) {
          selectedIndex = 1;
        } else {
          selectedIndex = 0;
        }
        return views[selectedIndex];
      },
    );
  }
}
